package com.ucar.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ucar.R;
import com.ucar.bean.Area;

public class AreaAdapter extends AbstractAdapter<Area> 
{
	public AreaAdapter(Context mContext) 
	{
		super(mContext);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		final ViewHolder holder;
		if ( convertView == null )
		{
			convertView = LayoutInflater.from( mContext ).
					inflate( R.layout.item_select_area, null );
			holder = new ViewHolder( convertView );
			convertView.setTag( holder );
		}
		else
		{
			holder = (ViewHolder) convertView.getTag();
		}
		
		Area area = getItem(position);
		holder.tvAreaName.setText( area.getName() );
		holder.tvDistance.setText( area.getKm() + "km" );
		return convertView;
	}
	
	public static class ViewHolder
	{
		TextView tvAreaName;
		TextView tvDistance;
		
		public ViewHolder ( View view )
		{
			tvAreaName = (TextView) view.findViewById( R.id.tv_area_name );
			tvDistance = (TextView) view.findViewById( R.id.tv_distance );
		}
	}

}
